library(nnet)

## 取得数据集
seeds<-read.table("seed.txt",header=FALSE,sep="")
names(seeds)<-c("A","P","C","L","W","AC","LKG","Label")

## 训练集和测试集
trainindex<-sample(1:210,147)
testindex<-setdiff(1:210,trainindex)

## 构建模型
ideal<-class.ind(seeds$Label)
seedsANN<-nnet(seeds[trainindex,-8],ideal[trainindex,],size=10,softmax=TRUE) #-8表示去掉第八列

## 用模型对测试数据进行测试
testLabel<-predict(object=seedsANN,newdata=seeds[testindex,-8],type="class")

## 模型评价
my_table<-table(seeds[testindex,]$Label,testLabel)
test_arror<-1-sum(diag(my_table))/sum(my_table)
